/**
 * Created with IntelliJ IDEA
 * Description:
 * User: Administrator
 * Data: 2023 - 05 - 14
 * Time: 12:20
 */
public class Practice {
        public int missingNumber(int[] nums) {
            int n = nums.length + 1;
            int sum1 = (0 + (n - 1)) * n / 2;
            int sum2 = 0;
            for(int j = 0; j < nums.length; j++) {
                sum2 += nums[j];
            }
            return sum1 - sum2;
        }
}
class Solution {
    public void rotate(int[] nums, int k) {
        k %= nums.length;//注意k是非负数，不一定比数组长度大
        reserve(nums, 0, nums.length - 1);
        reserve(nums, 0, k - 1);
        reserve(nums, k, nums.length - 1);
    }
    public void reserve(int[] nums, int left, int right) {
        while(left < right) {
            int tmp = nums[left];
            nums[left] = nums[right];
            nums[right] = tmp;
            left++;
            right--;
        }
    }
}
